import './public-path'
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'

import { RouterProvider } from 'react-router'
import { router } from './router'

import {
  renderWithQiankun,
  qiankunWindow
} from 'vite-plugin-qiankun/dist/helper'

console.log("qiankunWindow.__POWERED_BY_QIANKUN__",qiankunWindow.__POWERED_BY_QIANKUN__)

const initQianKun = () => {
  renderWithQiankun({
    mount(props) {
      render(props.container)
    },
    update() {},
    bootstrap() {},
    unmount() {}
  })
}

const render = (container?: HTMLElement | null) => {
  const appDom = container ? container : document.getElementById('root')
  createRoot(appDom!).render(
    <StrictMode>
      <RouterProvider router={router}></RouterProvider>
    </StrictMode>
  )
}

qiankunWindow.__POWERED_BY_QIANKUN__ ? initQianKun() : render()